package View;

import java.awt.Color;
import javax.swing.JFrame;

import Model.SimModel;

import sim.display.Controller;
import sim.display.Display2D;
import sim.display.GUIState;
import sim.engine.SimState;
import sim.portrayal.Inspector;
import sim.portrayal.grid.SparseGridPortrayal2D;

public class SimView extends GUIState {
	public int FRAME_SIZE = 400;
	public Display2D display;
	public JFrame displayFrame;
	
	SparseGridPortrayal2D yardPortrayal = new SparseGridPortrayal2D();
	
	public SimView(SimState state) {
		super(state);
	}
	
	public void start() {
		super.start(); 
		setupPortrayals();
	}
	
	public void load(SimState state) {
		
	}
	
	//Description des objets
	public void setupPortrayals() {
		SimModel model = (SimModel) state;
		
		yardPortrayal.setField(model.yard);
		//yardPortrayal.setPortrayalForClass(Human.class, getHumanPortrayal());
		//yardPortrayal.setPortrayalForClass(Corpse.class, getCorpsePortrayal());
		//yardPortrayal.setPortrayalForClass(Zombie.class, getZombiePortrayal());
		
		// Initialisation du plateau (background)
		/*ImageIcon imageIcon = new ImageIcon("img/yard.jpg");
		Image background = imageIcon.getImage();
		int dimension = (int)Math.min(model.yard.getWidth(), model.yard.getHeight());
		yardPortrayal.setPortrayalForAll(new ImagePortrayal2D(background, dimension));*/
		
		display.reset();
		display.setBackdrop(Color.WHITE);
		//display.setBackdrop(null);
		//display.attach(yardPortrayal, "Overlay");
		display.repaint();
	}
	
	public Object getSimulationInspectedObject() { return state; }	
	public Inspector getInspector()
	{
		Inspector i = super.getInspector();
		i.setVolatile(true);
		return i;
	}
	
	public void init(Controller c) {
		super.init(c);
		display = new Display2D(FRAME_SIZE, FRAME_SIZE, this);
		display.setClipping(false);
		
		displayFrame = display.createFrame();
		displayFrame.setTitle("Zombie outbreak simulation");
		c.registerFrame(displayFrame);
		displayFrame.setVisible(true);
		
		display.attach( yardPortrayal, "Yard" );
	}
	
	//Visualisation des agents -> Humain yellow
	/*private OvalPortrayal2D getHumanPortrayal() {
		OvalPortrayal2D r = new OvalPortrayal2D();
		r.paint = Color.YELLOW;
		r.filled = true; 
		return r;
	}*/
	
	//Visualisation des agents -> Corpse black
	/*private OvalPortrayal2D getCorpsePortrayal() {
		OvalPortrayal2D r = new OvalPortrayal2D();
		r.paint = Color.BLACK;
		r.filled = true;
		return r;
	}*/
	
	//Visualisation des agents -> Zombie red
	/*private OvalPortrayal2D getZombiePortrayal() {
		OvalPortrayal2D r = new OvalPortrayal2D();
		r.paint = Color.RED;
		r.filled = true;
		return r;
	}*/
}